package com.kdtech.analyse.common;

import com.kdtech.utils.StringUtils;

public class ProcessRule {
	ProcessType processType;
	private String param1;
	private String param2;

	public ProcessRule(ProcessType processType,String param1, String params2) {
		this.processType = processType;
		this.param1 = param1;
		this.param2 = params2;
		
	}
	public static ProcessRule replace(String param1,String params2){
		return new ProcessRule(ProcessType.REPLACE,param1,params2);
	}
	public static ProcessRule substringBefore(String param1){
		return new ProcessRule(ProcessType.SUBSTRING_BEFORE,param1,null);
	}
	public static ProcessRule substringBeforeLast(String param1){
		return new ProcessRule(ProcessType.SUBSTRING_BEFORE_LAST,param1,null);
	}
	public static ProcessRule substringAfter(String param1){
		return new ProcessRule(ProcessType.SUBSTRING_AFTER,param1,null);
	}
	public static ProcessRule substringAfterLast(String param1){
		return new ProcessRule(ProcessType.SUBSTRING_AFTER_LAST,param1,null);
	}
	public static ProcessRule substringBetween(String param1,String params2){
		return new ProcessRule(ProcessType.SUBSTRING_BETWEEN,param1,params2);
	}
	
	
	
	public String getString(String str){
		switch (processType) {
		case REPLACE:
			return StringUtils.replace(str, param1, param2);
		case SUBSTRING_BEFORE:
			return StringUtils.substringBefore(str, param1);
		case SUBSTRING_BEFORE_LAST:
			return StringUtils.substringBeforeLast(str, param1);
		case SUBSTRING_AFTER:
			return StringUtils.substringAfter(str, param1);
		case SUBSTRING_AFTER_LAST:
			return StringUtils.substringAfterLast(str, param1);
		case SUBSTRING_BETWEEN:
			return StringUtils.substringBetween(str, param1, param2);
		}
		return str;
	}
	

}
